package inventory.view;

import java.awt.Color;
import java.awt.event.ActionListener;

import javax.swing.AbstractListModel;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;

import javax.swing.SpringLayout;
import javax.swing.border.LineBorder;
import javax.swing.table.DefaultTableModel;

public class Inward extends JPanel
{
	private JTable table;
	private JList list;
	private JButton btnSave;
	
	public Inward() 
	{
		SpringLayout sl_this = new SpringLayout();
		this.setLayout(sl_this);
		
		JScrollPane scrollPane = new JScrollPane();
		sl_this.putConstraint(SpringLayout.NORTH, scrollPane, 10, SpringLayout.NORTH, this);
		sl_this.putConstraint(SpringLayout.WEST, scrollPane, 121, SpringLayout.WEST, this);
		sl_this.putConstraint(SpringLayout.SOUTH, scrollPane, -36, SpringLayout.SOUTH, this);
		sl_this.putConstraint(SpringLayout.EAST, scrollPane, -10, SpringLayout.EAST, this);
		this.add(scrollPane);
		
		table = new JTable();
		table.setModel(new DefaultTableModel(
			new Object[][] {
			},
			new String[] {
				"SR NO.", "ITEMS", "SPECIFICATION", "UNIT", "QTY"
			}
		) {
			boolean[] columnEditables = new boolean[] {
				false, false, false, false, true
			};
			public boolean isCellEditable(int row, int column) {
				return columnEditables[column];
			}
		});
		table.getColumnModel().getColumn(1).setPreferredWidth(136);
		table.getColumnModel().getColumn(2).setPreferredWidth(113);
		table.getColumnModel().getColumn(4).setPreferredWidth(54);
		scrollPane.setViewportView(table);
		
		btnSave = new JButton("SAVE");
		sl_this.putConstraint(SpringLayout.NORTH, btnSave, 3, SpringLayout.SOUTH, scrollPane);
		sl_this.putConstraint(SpringLayout.EAST, btnSave, -285, SpringLayout.EAST, this);
		this.add(btnSave);
		
		JLabel lblOpenGins = new JLabel("Open Gins");
		sl_this.putConstraint(SpringLayout.NORTH, lblOpenGins, 0, SpringLayout.NORTH, scrollPane);
		sl_this.putConstraint(SpringLayout.WEST, lblOpenGins, 10, SpringLayout.WEST, this);
		this.add(lblOpenGins);
		
		list = new JList();
		sl_this.putConstraint(SpringLayout.NORTH, list, 2, SpringLayout.SOUTH, lblOpenGins);
		sl_this.putConstraint(SpringLayout.SOUTH, list, -36, SpringLayout.SOUTH, this);
		list.setBorder(new LineBorder(new Color(0, 0, 0)));
		sl_this.putConstraint(SpringLayout.WEST, list, 10, SpringLayout.WEST, this);
		sl_this.putConstraint(SpringLayout.EAST, list, 100, SpringLayout.WEST, this);
		list.setModel(new AbstractListModel() {
			String[] values = new String[] {"ITEM 1", "ITEM 2", "ITEM 3", "ITEM 4", "ITEM 5"};
			public int getSize() {
				return values.length;
			}
			public Object getElementAt(int index) {
				return values[index];
			}
		});
		
		this.add(list);
		list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 	
	}
	

	public JTable getTable() {
		return table;
	}

	public void setTable(JTable table) {
		this.table = table;
	}


	public JList getList() {
		return list;
	}



	public void setList(JList list) {
		this.list = list;
	}


	public JButton getBtnSave() {
		return btnSave;
	}



	public void setBtnSave(JButton btnSave) {
		this.btnSave = btnSave;
	}

	
	//*********************************************************************************
	public void addActionListener(ActionListener al)
	{
		this.btnSave.addActionListener(al);
	}
	
}
